package com.huawei.appmarket.framework.startevents.protocol;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;
import androidx.fragment.app.Fragment;
import com.huawei.appgallery.foundation.account.bean.UserSession;
import com.huawei.appgallery.foundation.ui.framework.activity.BaseActivity;
import com.huawei.appgallery.foundation.ui.framework.fragment.LoadingFragment;
import com.huawei.appgallery.foundation.ui.framework.titleframe.bean.BaseTitleBean;
import com.huawei.appmarket.R;
import com.huawei.appmarket.framework.titleframe.title.ContentTitle;
import com.huawei.appmarket.service.settings.card.SettingChangeHomecountryCard.a;
import com.huawei.appmarket.service.settings.card.SettingChangeHomecountryCard.d;
import com.huawei.cloudservice.CloudAccount;
import com.huawei.cloudservice.IntentResultHandler;
import com.huawei.hwid.core.constants.HwAccountConstants;
import com.huawei.hwid.core.helper.handler.ErrorStatus;
import com.huawei.updatesdk.service.otaupdate.UpdateStatusCode.DialogButton;
import huawei.widget.HwButton;
import o.bkt;
import o.bod;
import o.AccountBussinessListener;
import o.ccp;
import o.ccz;
import o.cjf;
import o.dgh;
import o.dgm;
import o.dhq;
import o.dit;
import o.diu;
import o.Logger;
import o.dof;
import o.ContentManager;
import o.dvt;
import o.dzv;
import o.eec;
import o.egn;
import o.egv;
import o.ekg;
import o.eod;
import o.eoj;
import o.eop;
import o.eos;
import o.eqn;
import o.eqp;
import o.eqq;
import o.euf;
import o.evx;

public class ServiceZoneSwitchActivity extends BaseActivity<ServiceZoneSwitchActivityProtocol> implements eqn, a, dit {
    private View ˋॱ;
    private int ˏॱ = ccz.ॱ();
    private HwButton ॱˊ;

    public void onCreate(Bundle bundle) {
        String str;
        CharSequence charSequence = null;
        super.onCreate(bundle);
        setContentView(R.layout.service_zone_switch);
        getWindow().getDecorView().setBackgroundColor(getResources().getColor(R.color.emui_white));
        ServiceZoneSwitchActivityProtocol serviceZoneSwitchActivityProtocol = (ServiceZoneSwitchActivityProtocol) ʾ();
        if (serviceZoneSwitchActivityProtocol == null || serviceZoneSwitchActivityProtocol.ॱ() == null) {
            str = null;
        } else {
            String ॱ = serviceZoneSwitchActivityProtocol.ॱ().ॱ();
            String ˋ = serviceZoneSwitchActivityProtocol.ॱ().ˋ();
            this.ˏॱ = serviceZoneSwitchActivityProtocol.ॱ().ˊ();
            str = ˋ;
            charSequence = ॱ;
        }
        if (TextUtils.isEmpty(str)) {
            str = getString(R.string.app_name);
        }
        if (TextUtils.isEmpty(charSequence)) {
            charSequence = getString(R.string.service_zone_no_support);
        }
        if (this.ˏॱ == 17) {
            Logger.ˎ("ServiceZoneSwitchActivity", "setActivityID, Type = INNER_KIDS_CENTER, serviceType = " + this.ˏॱ);
            dgm.ˋ(this.ˏॱ, this, R.string.kidschannel_app_name, "kidscenter.activity");
        } else if (this.ˏॱ == 18) {
            Logger.ˎ("ServiceZoneSwitchActivity", "setActivityID, Type = INNER_EDUCATION_CENTER, serviceType = " + this.ˏॱ);
            dgm.ˋ(this.ˏॱ, this, R.string.educhannel_app_name, "educenter.activity");
        }
        ॱ(str);
        ((TextView) findViewById(R.id.app_service_switch_textview)).setText(charSequence);
        this.ॱˊ = (HwButton) findViewById(R.id.service_switch_button);
        this.ˋॱ = findViewById(R.id.loading_root);
        this.ॱˊ.setOnClickListener(new evx(this) {
            final /* synthetic */ ServiceZoneSwitchActivity ˊ;

            {
                this.ˊ = r1;
            }

            public void ˋ(View view) {
                if (UserSession.getInstance().isLoginSuccessful()) {
                    this.ˊ.ˎ(1);
                    return;
                }
                eoj.ˋ().ˎ("ServiceZoneSwitchActivity", new AccountBussinessListener(this) {
                    final /* synthetic */ AnonymousClass5 ˏ;

                    {
                        this.ˏ = r1;
                    }

                    public void onAccountBusinessResult(ccp o_ccp) {
                        if (102 == o_ccp.ˎ) {
                            eoj.ˋ().ˊ("ServiceZoneSwitchActivity");
                        } else if (DialogButton.CONFIRM == o_ccp.ˎ) {
                            eoj.ˋ().ˊ("ServiceZoneSwitchActivity");
                        }
                        this.ˏ.ˊ.ॱˊ();
                    }
                });
                this.ˊ.ᐝ();
                eqq.ˋ().ˎ("ServiceZoneSwitchActivity", this.ˊ);
                eod.ˊ(view.getContext(), null, false, true, true);
            }
        });
    }

    public cjf ˊ(String str) {
        BaseTitleBean baseTitleBean = new BaseTitleBean();
        baseTitleBean.ॱ(str);
        return new ContentTitle(this, baseTitleBean);
    }

    public void onResult(int i) {
        Logger.ˎ("ServiceZoneSwitchActivity", "ServiceZoneSwitchActivity onResult " + i);
        if (i == 202) {
            Logger.ˎ("ServiceZoneSwitchActivity", "ServiceZoneSwitchActivity onResult GO changeHomeCountry.");
            ॱˊ();
            ˎ(1);
        }
        eqq.ˋ().ˊ("ServiceZoneSwitchActivity");
    }

    private void ˎ(final int i) {
        Context ˋ = ContentManager.getInstant().getContext();
        IntentResultHandler dVar = new d(this, this.ˏॱ, this, i, new Runnable(this) {
            final /* synthetic */ ServiceZoneSwitchActivity ॱ;

            public void run() {
                this.ॱ.ˎ(i - 1);
            }
        });
        CloudAccount ˊ = eos.ˊ();
        if (ˊ != null) {
            Logger.ˎ("ServiceZoneSwitchActivity", "getHomeCountryChangeIntent");
            ˊ.getHomeCountryChangeIntent(ˋ, dVar);
        }
    }

    public void onActivityResult(int i, int i2, Intent intent) {
        super.onActivityResult(i, i2, intent);
        if (i == 10008 && intent != null) {
            if (-1 == i2) {
                String stringExtra = intent.getStringExtra(HwAccountConstants.EXTRA_SERVICE_COUNTRY);
                String ॱ = eqp.ॱ();
                if (dof.ˋ(stringExtra) || stringExtra.equalsIgnoreCase(ॱ)) {
                    Logger.ˋ("ServiceZoneSwitchActivity", "ServiceZoneSwitchActivity returnHomeCountry is blank");
                    return;
                }
                dgh.ˏ();
                diu.ˊ().ॱ();
                ((bod) bkt.ˋ("DynamicCore", bod.class)).ˎ();
                dvt.ˏ().ˋ(1);
                dhq.ॱ().ˊ();
                euf.ˎ().ॱॱ();
                ekg.ॱ().ˏ();
                egv.ॱᐝ().ˏॱ();
                UserSession.getInstance().setHomeCountry(stringExtra);
                eop.ˎ(UserSession.getInstance());
                egn.ˎ().ॱ();
                eec.ˊ().ˏ();
                ॱ = "app_market";
                if (this.ˏॱ == 17) {
                    ॱ = "app_child";
                } else if (this.ˏॱ == 18) {
                    ॱ = "app_edu";
                }
                Logger.ˎ("ServiceZoneSwitchActivity", "ServiceZoneSwitchActivity restartApplication restartFrom=" + ॱ);
                dzv.ˊ(ॱ);
                return;
            }
            ErrorStatus errorStatus = (ErrorStatus) intent.getParcelableExtra(HwAccountConstants.EXTRA_PARCE);
            if (errorStatus != null) {
                Logger.ˋ("GLOBAL_START_FLOW", "onError errorCode:" + errorStatus.getErrorCode() + ", errorReason:" + errorStatus.getErrorReason());
                return;
            }
            Logger.ˋ("GLOBAL_START_FLOW", "ServiceZoneSwitchActivity errStatus is null");
        }
    }

    public void onDestroy() {
        Logger.ˏ("ServiceZoneSwitchActivity", "renewTaskID: serviceType = " + this.ˏॱ);
        dgm.setEnd(this.ˏॱ);
        eoj.ˋ().ˊ("ServiceZoneSwitchActivity");
        super.onDestroy();
    }

    public void ᐝ() {
        try {
            new LoadingFragment().ˋ(ˏॱ(), R.id.loading_root, "ServiceZoneSwitchActivity");
            this.ˋॱ.setVisibility(0);
        } catch (Throwable e) {
            Logger.ˋ("ServiceZoneSwitchActivity", "showLoading, e: ", e);
        }
    }

    public void ॱˊ() {
        Fragment findFragmentByTag = ˏॱ().findFragmentByTag("ServiceZoneSwitchActivity");
        if (findFragmentByTag != null) {
            ˏॱ().ˊ().ॱ(findFragmentByTag);
        }
        this.ˋॱ.setVisibility(8);
    }

    public void ͺ() {
    }

    public void ᐝॱ() {
    }

    public int ˊ() {
        return this.ˏॱ;
    }
}
